package com.xctech.yace.service;


import com.xctech.yace.dto.MetaDataDTO;
import com.xctech.yace.factory.MybatisSessionFactory;
import com.xctech.yace.mapper.MetaDataMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.util.List;
import java.util.Map;
import java.util.Properties;

@Slf4j
public class TradeO32Service {

    /**
     * 获取查询出来的数据
     * @param sql
     * @param properties
     * @return
     */
    public static List<Map<String,Object>> selectSql(String sql, Properties properties){

        SqlSession sqlSession = null;
        List<Map<String,Object>> maps = null;
        try{
            //初始化sqlSession
            sqlSession = MybatisSessionFactory.getSqlSessionFactory(properties).openSession();
            MetaDataMapper mapper = sqlSession.getMapper(MetaDataMapper.class);
            maps = mapper.selectSql(sql);
        }catch (Exception e){
            log.error(e.getMessage(),e);
        }finally{
            if(sqlSession != null){
                sqlSession.close();
            }
        }

        return maps;
    }

    /**
     * 获取基础信息
     * @param xid
     * @param properties
     * @return
     */
    public static List<MetaDataDTO> select(String xid, Properties properties){

        SqlSession sqlSession = null;
        List<MetaDataDTO> metaDataList = null;
        try{
            //初始化sqlSession
            sqlSession = MybatisSessionFactory.getSqlSessionFactory(properties).openSession();
            MetaDataMapper mapper = sqlSession.getMapper(MetaDataMapper.class);

            metaDataList = mapper.getMetaDataList(xid);

        }catch (Exception e){
            log.error(e.getMessage(),e);
        }finally{
            if(sqlSession != null){
                sqlSession.close();
            }
        }

        return metaDataList ;
    }




}
